/**
 * @Copyright:Copyright (c) 1992 - 2015
 * @Company: TengTong
 */
package com.tengtong.duang.commons.convert;

import com.tengtong.duang.commons.convert.support.ArrayToNumberConverter;
import com.tengtong.duang.commons.convert.support.ArrayToStringConverter;
import com.tengtong.duang.commons.convert.support.BigDecimalToNumberConverter;
import com.tengtong.duang.commons.convert.support.BigIntegerToNumberConverter;
import com.tengtong.duang.commons.convert.support.CollectionToArrayConverter;
import com.tengtong.duang.commons.convert.support.CollectionToMapConverter;
import com.tengtong.duang.commons.convert.support.CollectionToStringConverter;
import com.tengtong.duang.commons.convert.support.DateGenericConverter;
import com.tengtong.duang.commons.convert.support.DateToStringConverter;
import com.tengtong.duang.commons.convert.support.StringGenericConverter;
import com.tengtong.duang.commons.convert.support.StringToArrayConverter;
import com.tengtong.duang.commons.convert.support.StringToBooleanConverter;
import com.tengtong.duang.commons.convert.support.StringToCollectionConverter;
import com.tengtong.duang.commons.convert.support.StringToEnumConverter;
import com.tengtong.duang.commons.convert.support.StringToNumberConverter;

/**
 * 这是转换工厂，提供静态方法方便使用
 *
 * @author jai
 * @since: v1.0
 */
public class ConversionServiceFactory {

	/**
	 * 创建一个缺省 ConversoinService 提供使用
	 * @return
	 */
	public static ConversionService createDefaultConversionService(){
		ConversionService service = new ConversionService();
		addDefaultConverter(service);
		
		return service;
	}

	/**
	 * 添加内置，已经创建好的转换器
	 *
	 * @param service
	 */
	private static void addDefaultConverter(ConversionService service) {
		service.addConverter(new StringGenericConverter());
		service.addConverter(new DateGenericConverter());
		service.addConverter(new StringToBooleanConverter());
		service.addConverter(new StringToEnumConverter());
		service.addConverter(new StringToNumberConverter());
		service.addConverter(new BigIntegerToNumberConverter());
		service.addConverter(new BigDecimalToNumberConverter());
		service.addConverter(new ArrayToStringConverter(service));
		service.addConverter(new CollectionToStringConverter(service));
		service.addConverter(new StringToArrayConverter(service));
		service.addConverter(new StringToCollectionConverter());
		service.addConverter(new ArrayToNumberConverter(service));
		service.addConverter(new CollectionToArrayConverter(service));
		service.addConverter(new CollectionToMapConverter());
		
		service.addConverter(new DateToStringConverter());
		
	}
	
}
